package xin.lhuo.we.server.utils;

import org.springframework.util.StringUtils;

import java.util.HashMap;

/**
 * @author Lhuo
 * @date 2019/5/26 17:40
 */
public class MimeTypeUtil {
    private static HashMap<String, String> mimeTypeMap = new HashMap<>();

    static {
        mimeTypeMap.put("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "excel");
        mimeTypeMap.put("application/vnd.openxmlformats-officedocument.spreadsheetml.template", "excel");
        mimeTypeMap.put("application/vnd.ms-excel.addin.macroEnabled.12", "excel");
        mimeTypeMap.put("application/vnd.ms-excel", "excel");
        mimeTypeMap.put("application/vnd.ms-excel.sheet.binary.macroEnabled.12", "excel");
        mimeTypeMap.put("application/vnd.openxmlformats-officedocument.presentationml.template", "ppt");
        mimeTypeMap.put("application/vnd.openxmlformats-officedocument.presentationml.slideshow", "ppt");
        mimeTypeMap.put("application/vnd.openxmlformats-officedocument.presentationml.presentation", "ppt");
        mimeTypeMap.put("application/vnd.ms-powerpoint", "powerpoint");
        mimeTypeMap.put("application/vnd.openxmlformats-officedocument.presentationml.slide", "ppt");
        mimeTypeMap.put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", "word");
        mimeTypeMap.put("application/vnd.openxmlformats-officedocument.wordprocessingml.template", "word");
        mimeTypeMap.put("application/msword", "word");
        mimeTypeMap.put("text/plain", "text");
        mimeTypeMap.put("application/pdf", "pdf");
    }

    public static String getSimpleType(String mimeType) {
        String simpleType = mimeTypeMap.get(mimeType);
        if (StringUtils.isEmpty(simpleType)) {
            simpleType = "other";
        }
        return simpleType;
    }
}
